package chapter_06_prototype;

/**
 * @author yaochenglong
 * @date 2019/8/8
 */
public class Dog implements Cloneable{

    private String name;
    private int age;

    public Dog() {
    }

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 要使用clone方法，必须实现cloneable接口，否则会报错CloneNotSupportedException
     * @return
     * @throws CloneNotSupportedException
     */
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        Dog dog = new Dog();
        Dog copy = (Dog) dog.clone();
    }
}
